package com.wantup.springboot.boot.jms.mkw.jms_activemq.springjms.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import javax.annotation.Resource;
import javax.jms.*;

import static java.lang.System.out;

/**
 * @author zhapluowei
 * @date 2018-11-16 0:19
 */
public class ProducerServiceImpl implements ProducerService {

    @Autowired
    private JmsTemplate jmsTemplate;

    //提供目的地
    //@Resource(name = "queueDestination")//队列模式
    @Resource(name = "topicDestination")
    private Destination destinationl;

    @Override
    public void sendMessage(String message) {
        //就可以发送消息了
        jmsTemplate.send(destinationl, new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                TextMessage textMessage = session.createTextMessage(message);
                return textMessage;
            }
        });
                out.println("发送消息 ："+message);
    }
}
